package mo.gov.macaupost.seps;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import mo.gov.macaupost.seps.commons.AppConstants;
import mo.gov.macaupost.seps.object.UserSession;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;

public class LoginActivity extends Activity {
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_login, menu);
        return true;
    }
    
    public void sepbox_login(){
    	try {
	    	UserSession user_session = new UserSession();
	    	EditText et_postid = (EditText)findViewById(R.id.editText_login_postid);
	    	user_session.setPostid(et_postid.getText().toString());
	    	EditText et_password = (EditText)findViewById(R.id.editText_login_password);
	    	user_session.setPassword(et_password.getText().toString());
	    	
	    	HttpPost http_request = new HttpPost(AppConstants.sepbox_login_url);
	    	List<NameValuePair> params = new ArrayList<NameValuePair>();
	    	params.add(new BasicNameValuePair("user",user_session.getPostid()));
	    	params.add(new BasicNameValuePair("password",user_session.getPassword()));
	    	
	    	http_request.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
	    	HttpResponse http_response = new DefaultHttpClient().execute(http_request);
	    	String result = EntityUtils.toString(http_response.getEntity());
	    	
	    	System.out.println(result);
    	} catch (Exception e){
    		
    	}
    }
        
}
